<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<title>添加题目</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="../layui/css/layui.css" media="all">
	<style>
		/*添加题目页面样式 */
		.addTitle-con{
			padding: 0 15px 15px 15px;
		}
		.addTitle-con .layui-tab-content{
			width: 95%;
			margin: auto;
			padding: 10px;
			margin-top: 10px;
			clear: both;
			background-color: #F2F2F2;
		}
		.addTitle-con .addTitle-top{
			padding-top: 15px;
		}
		.addTitle-con .top-inp{
			margin-left: 20px;
		}
		.addTitle-con .from-con .layui-form-item{
			margin-bottom: 30px;
		}
		.addTitle-con .not_border_left {
			border-left: none !important;
		}
		/* 下拉框最大高度 */
		.addTitle-con .layui-col-xs6 .layui-form-select dl{   
			max-height: 170px !important;
		}
		.addTitle-con .layui-form-item .layui-input-block .required {
			color: red; 
			font-size: 32px; 
			float: left; 
			margin-left: 5px; 
			margin-top: 5px;
			position: absolute;
			right: -15px;
		}
		.addTitle-con .layui-form-select dl dd.layui-this{
			background-color: #1E9FFF !important;
		}
		.addTitle-con .layui-tab-title{
			border: none !important;
		}
		.addTitle-con .layui-tab-content{
			padding: 0px !important;
			padding-top: 10px !important;
		}
	</style>
</head>
<body>
	<div class="layui-tab layui-tab-brief addTitle-con" lay-filter="docDemoTabBrief">
	  <ul class="layui-tab-title">
	    <li class="layui-this">添加题目</li>
	    <li style="display: none;">批量导入题目</li>
	  </ul>
	  <div class="layui-tab-content">
	  	<div class="layui-row">
			<div class="layui-col-xs1">
			</div>
			<div class="layui-col-xs11">
		    	<div class="layui-tab-item layui-show">
					<div class="from-con">
						<form class="layui-form addTitle-top" action="" id="formaddtea">
							<div class="layui-form-item">
							    <label class="layui-form-label">维度编号</label>
							    <div class="layui-input-inline">
							      	<select name="dimension" id="dimension" lay-filter="dimension" lay-event="dimension">
							        	<option value="00">请选择维度</option>
							    	</select>	
							    </div>
							    <label class="layui-form-label">所属卷类</label>
							    <div class="layui-input-inline">
							      	<select name="volClass" id="volClass" lay-filter="volClass" lay-event="volClass">
							        	<option value="00">请选择卷类</option>
							    	</select>	
							    </div>
							</div>
						</form>
						<fieldset class="layui-elem-field layui-field-title">
						  <legend>题目录入</legend>
						</fieldset>
						<form class="layui-form" action="" id="formaddtea">
						    <div class="layui-form-item">
							    <label class="layui-form-label">题目名称</label>
							    <div class="layui-input-block">
							      <input id="title" type="text" style="float: left;position: relative;" name="title" lay-verify="required" placeholder="请输入题目名称" class="layui-input" autocomplete="off">
							      <i class="required">*</i>
							    </div>
						  	</div>
						  	<div class="layui-form-item">
						  		<label class="layui-form-label">题目类型</label>
							    <div class="layui-input-block">
							      	<select name="tilType" id="tilType" lay-filter="required" lay-event="volClass">
							        	<option value="00">请选择题目类型</option>
							        	<option value="1">选择题</option>
							    	</select>	
							    </div>
						  	</div>
							<div class="layui-form-item">
							    <label class="layui-form-label">题库排序号</label>
							    <div class="layui-input-block">
							      	<input id="sort" type="number" name="sort" placeholder="请输入题库排序号" class="layui-input" autocomplete="off" min="0">
							    </div>
							</div>
							<div class="layui-form-item">
							    <label class="layui-form-label">题目描述</label>
							    <div class="layui-input-block">
							      <textarea id="describe" placeholder="请题目描述内容" class="layui-textarea"></textarea>
							    </div>
							</div>
							<div class="layui-form-item">
							    <div class="layui-input-block">
									<button type="button" id="addtitle" name="addtitle" lay-submit="" lay-filter="addtitle" class="layui-btn layui-btn-normal" style="float: right;"> 保  存 </button>
							    </div>
							</div>
						</form>
					</div>
				</div>
				
				<!-- 批量导入题目 -->
				<div class="layui-tab-item">
					<div class="layui-block">
						<div class="layui-form-item">
							<form class="layui-form" action="">
								<div class="layui-input-inline">
								    <select name="seldim" id="seldim" lay-filter="seldim">
								    	<option value=''>请选择维度</option>
									</select>
								</div>
								<div class="layui-input-inline">
								    <select name="selType" id="selType" lay-filter="selType">
								    	<option value=''>请选择卷类</option>
									</select>
								</div>
								<div class="layui-input-inline">
								    <select name="selType" id="selType" lay-filter="selType">
								    	<option value=''>请选择题型</option>
									</select>
								</div>
								<button type="button" class="layui-btn" id="uploadbtn">选择Excel文件</button>
								<button type="button" class="layui-btn" id="test4" style="display: none;">
									<i class="layui-icon"></i>选择Excel文件
								</button>
								<button type="button" class="layui-btn layui-btn-primary" lay-submit="" lay-filter="downloadTitle" id="downloadTitle" style="float: right;">下载模板</button>
								<button type="button" class="layui-btn savebtn" lay-submit="" lay-filter="saveTitleList" id="saveTitleList">保存</button>
							</form>
						</div>
					</div>
					<table class="layui-hide" id="titleList"></table>
				</div>
			</div>
			<div class="layui-col-xs1">
			</div>
		</div>
	  </div>
	</div>
	
	<script src="../js/jquery-3.3.1.js"></script>
	<script src="../layui/layui.all.js"></script>
	<script>
		layui.use(['form','laydate','upload'], function(){
			var form = layui.form, laydate = layui.laydate,
			upload = layui.upload, table = layui.table;
			
			/*加载维度下拉框*/
			$.ajax({
				type : 'get',
				url : '../dimensionmanagement/getalldimensionlist',
				datatype : 'json',
				success : function(dimension) {
					if (dimension.code == 0) {
						var str = "";
						for(var i = 0; i < dimension.count; i++){
							str += '<option value=' + dimension.data[i].dimensionid + '>'+ dimension.data[i].dimensionName+'</option>';
						}
						$("#dimension").append(str);
						form.render("select");
					}
				}
			});
			form.on('select(dimension)', function(data) {
				var dimension = data.value;
				if(dimension == 00) {
					dimension = "";
				}
				if(dimension == ""){
					return;
				}
				/*动态加载卷类下拉框*/
				$("#volClass").html("");
				$.ajax({
					type: 'get',
					url: '../scaletitletype/getScaletitletypebydropdown?dimensionid=' + dimension,
					datatype: 'json',
					success: function(voldata) {
						if(voldata.code == 0) {
							var str = "<option value='00'>请选择卷类</option>";
							for(var i = 0; i < voldata.count; i++) {
								str += '<option value=' + voldata.data[i].id + '>' + voldata.data[i].name + '</option>';
							}
							$("#volClass").append(str);
							form.render("select");
						} else {
							$("#volClass").html("");
							layer.msg('暂无对应的卷类', {
								icon: 4
							});
							form.render("select");
						}
					}
				});
			});
			
			/* 上传题目文件 */
			$("#uploadbtn").click(function(){
				var seldim = $("#seldim").val();
				var selType = $("#selType").val();
				if(seldim == null || seldim == "" || seldim == "0"){
					layer.alert('请先选择维度！', {icon: 5});
					return;
				}
				if(selType == null || selType == "" || selType == "0"){
					layer.alert('请先选择题目类型！', {icon: 5});
					return;
				}
		    	$("#test4").click();
		   });
			
		    $("#test4").click(function(){
		    	var schoolid = $("#school").val();
		    	//指定允许上传的文件类型
				upload.render({ //允许上传的文件后缀
					elem : '#test4',
					url : '../systeachermanagement/getexceltablelist?schoolid=' + schoolid,
					accept : 'file', //普通文件
					exts : 'xls|xlsx|xlsm', //只允许上传压缩文件
					acceptMime : 'xls|xlsx|xlsm',
					done : function(res) {
						if (res.code == 0) {
							table.render({
								elem : '#teacher',
								url : '../systeachermanagement/excelloadtable?op=0',
								title : '教师数据表',
								skin : 'line',
								even : true,
								cols : [ [{
									type : 'numbers',
									title : '编号'
								}, {
									field : 'realName',
									title : '真实姓名'
								}, {
									field : 'sex',
									title : '性别'
								}, {
									field : 'email',
									title : '邮箱'
								}, {
									field : 'phone',
									title : '联系电话'
								}, {
									field : 'birthday',
									title : '生日'
								}, {
									field : 'entryTime',
									title : '入职时间',
								}] ]
							});
						} else {
		
						}
					}
				});
		    });
		    
		    /*保存导入的题目列表*/
			$("#saveTitleList").click(function() {
				$.ajax({
					type : 'get',
					url : '../systeachermanagement/savetealist',
					datatype : 'json',
					success : function(data) {
						if (data.code == 0) {
							layer.alert(data.msg, {icon: 1});							
						} else {
							layer.alert(data.msg, {icon: 2});						
						}
					},
					error : function() {
					}
				});
		
			});
			
			//添加一个题目
			form.on('submit(addtitle)', function(titledata){
				var title = $("#title").val();
				var voltype = $("#volClass").val();
				var tilType = $("#tilType").val();
				var sortNumber = $("#sort").val();
				var dimension = $("#dimension").val();
				var describe = $("#describe").val();
				
				if(title==00 || title==null || title=="" || title=='null'){
					layer.msg("请输入题目！"); 
					return false;
				}
				if(voltype==00 || voltype==null || voltype=="" || voltype=='null'){
					layer.msg("请选择所属卷类！"); 
					return false;
				}
				$.ajax({
					url: '../titlemanagement/addtitle',  
			        type: 'get', 
			        dataType: 'json',  
			        data:{titlename:title,titletype:tilType,
			        	titlenumber:sortNumber,paperType:voltype,
			        	dimensionid:dimension,titledescribe:describe},
			        success: function (data) {
			          if (data.code == "10001") {
			        	  layer.confirm("题目信息添加成功！", {
							  btn: ['确定'],icon:6
						  }, function(){
							  /*清空表单*/
				        	  $('form')[1].reset();
				        	  layer.closeAll();
						  });
			          }else { 
			        	  layer.alert("题目添加失败！",2);
			        	  return false;
			          }  
			        },
			        error:function(){
			        	layer.alert("题目添加失败！",2); 
			        }
				});
			    
			});
		});
	</script>
</body>
</html>